<template>
	<view style="background-color: #fff;">
		<view style="font-size: 35upx;text-align: center;padding: 0 50upx;">
			{{title}}
		</view>
		<view style="padding: 0 30upx;">
			<rich-text :nodes="content"></rich-text>
		</view>
		<view style="text-align: center;font-size: 35upx;">
			参与所需通证值:
			<text style="color: #f00;">{{tzz}}</text>
		</view>
		<view style="text-align: center;font-size: 35upx;">
			地址:
			<text style="color: #f00;">{{companyaddress}}</text>
		</view>
		<button v-if="status == 0" @click="getcoin" style="margin-top: 50upx;margin-bottom: 50upx; width: 80%;margin-left: 10%;background-color: #E22018;color: #fff;" type="default">立即兑换</button>
		<button v-if="status == 1" @click="getcontract" style="margin-top: 50upx;margin-bottom: 50upx; width: 80%;margin-left: 10%;background-color: #E22018;color: #fff;" type="default">请确认线下已签约</button>
	</view>
</template>

<script>
	export default {
	  data() {
	   return {
	    project:[],
			id:'',
			openid:'',
			content:'',
			company:'',
			companyaddress:'',
			title:'',
			tzz:'',
			status:'',
	   }
	  },
	  onLoad(options) {
			this.id = options.id
	    uni.getStorage({
	    	key: 'openid',
	    	success: (res) => {
	    		this.openid = res.data
	    		this.getarticle()
	    	},
	    	fail: () => {
	    		uni.navigateTo({
	    			url: '../login/login'
	    		});
	    	}
	    });
	  },
	  methods: {
			getarticle() {
				uni.request({
					url: this.$BASE_URL+'/index.php?i=2&c=entry&m=ewei_shopv2&do=mobile&r=tzz.project&app=1',
					method: 'POST',
					data: {
						'openid':this.openid,
						'id':this.id,
					},
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					success:(res) => {
						console.log(res)
						this.company = res.data.project.company
						this.content = res.data.project.content
						this.companyaddress = res.data.project.companyaddress
						this.title = res.data.project.title
						this.tzz = res.data.project.tzz
						this.status = res.data.status
					},
					fail: () => {},
					complete: () => {}
				});
			},
			getcoin() {
				uni.request({
					url: this.$BASE_URL+'/index.php?i=2&c=entry&m=ewei_shopv2&do=mobile&r=tzz.exchange_project&app=1',
					method: 'POST',
					data: {
						'openid':this.openid,
						'id':this.id,
					},
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					success:(res) => {
						console.log(res)
						uni.showToast({
							title:res.data.message,
							icon:'none'
						})
						setTimeout(()=> {
						uni.navigateTo({
							url: 'tzz'
						});
						}, 1000);
						
					},
					fail: () => {},
					complete: () => {}
				});
			},
			getcontract() {
				uni.request({
					url: this.$BASE_URL+'/index.php?i=2&c=entry&m=ewei_shopv2&do=mobile&r=tzz.sign&app=1',
					method: 'POST',
					data: {
						'openid':this.openid,
						'id':this.id,
					},
					header:{'Content-Type':'application/x-www-form-urlencoded'},
					success:(res) => {
						console.log(res)
						uni.showToast({
							title:res.data.message,
							icon:'none'
						})
						setTimeout(()=> {
						uni.navigateTo({
							url: 'tzz'
						});
						}, 1000);
						
					},
					fail: () => {},
					complete: () => {}
				});
			},
	  }
	 }
</script>

<style>
</style>
